﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shares/ShareSpace.master" AutoEventWireup="true" CodeFile="JSON.aspx.cs" Inherits="AjaxShowCase_JSON" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" Runat="Server">

    <button type='button' onclick='jsonToString()'>jsonToString</button>
    <button type='button' onclick='stringToJson()'>stringToJson</button>

    <script type="text/javascript">

        function jsonToString() {
            var cCar = Array();
            cCar.push('toyoutar');
            cCar.push('honda');
            var json = { 'name': 'Johny Bravo', 'age': 12, 'detail': { 'school': 'kkw', 'cars': cCar} }
            var str = JSON.stringify(json);
            alert(str);
        }

        function stringToJson() {
            var obj = $.parseJSON('{"name":"Johny Bravo"}');
            alert(obj.name === "Johny Bravo");
        }
        
    </script>

</asp:Content>

